package com.atguigu.spzx.manager.controller;

import com.atguigu.spyx.model.common.Result;
import com.atguigu.spyx.model.common.com.atguigu.spyx.model.entity.product.Category;
import com.atguigu.spzx.manager.service.CategoryService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author LT
 * @create 2023-11-07-20:46
 */
@RestController
@RequestMapping("/admin/product/category")
public class CategoryController {

    @Resource
    CategoryService categoryService;


    @GetMapping("export")
    public void exportCates(HttpServletResponse response){
        categoryService.exportCates(response);
    }

    @PutMapping("/updateById")
    public Result updateById(@RequestBody Category category){
        categoryService.updateById(category);
        return Result.ok();
    }

    @GetMapping("/getByCategoryId/{id}")
    public Result getByCategoryId(@PathVariable Long id){
        Category category = categoryService.getByCategoryId(id);
        return Result.ok().data(category);
    }

    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Long id){
        categoryService.deleteById(id);
        return Result.ok();
    }


    @PostMapping("/import")
    public Result importCates(MultipartFile excel){
        categoryService.importCates(excel);
        return Result.ok();
    }
    @GetMapping("findByPid/{pid}")
    public Result findByPid(@PathVariable("pid")Long pid){
        List<Category> categoryList = categoryService.findByPid(pid);
        return Result.ok().data(categoryList);
    }

}
